package ar.com.larreta.excepciones;

import java.io.PrintWriter;
import java.io.StringWriter;

import org.apache.log4j.Logger;

public class Excepcion extends Exception {

	protected static Logger logger;
	
	public Excepcion(String mensaje){
		super(mensaje);
		logger = Logger.getLogger(this.getClass());
		logger.error(getStackTrace(this));
	}
	
	public Logger getLogger(){
		return logger;
	}
	
	/**
	 * Retorna en un String la traza del error
	 * 
	 * @param e
	 * @return
	 */
	public static String getStackTrace(Throwable e) {
		StringWriter sWriter = new StringWriter();
		PrintWriter pilaMensajes = new PrintWriter(sWriter);
		e.printStackTrace(pilaMensajes);
		String stackTrace = sWriter.toString();
		return stackTrace;
	}
}
